// vue.config.js
const path = require('path')
const resolve = dir => path.join(__dirname, dir)
const WebpackBundleAnalyzer = require('webpack-bundle-analyzer')
module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : './',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: true, // 是否开启eslint保存检测
  productionSourceMap: false, // 是否在构建生产包时生成sourcdeMap
  chainWebpack: config => {
    config.resolve.alias /* 别名配置 */
      .set('@', resolve('src'))
      .set('@views', resolve('src/views'))
      .set('@components', resolve('src/components'))
      .set('@assets', resolve('src/assets'))
      .set('@mixins', resolve('src/mixins'))
      .set('@apis', resolve('src/apis'))
    config.optimization.runtimeChunk('single')
    //包分析工具
    if (process.env.use_analyzer) {
      config
        .plugin('webpack-bundle-analyzer')
        .use(WebpackBundleAnalyzer.BundleAnalyzerPlugin)
    }
    //开启gzip
    // config.plugin('CompressionPlugin').use(CompressionPlugin, [])
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: `
          @import '@/styles/variable.scss';
          @import '@/styles/mixins.scss';
          `
      }
    }
  },
  devServer: {
    disableHostCheck: true,
    // host: "localhost",
    /* 本地ip地址 */
    host: '0.0.0.0',
    port: '8888',
    hot: true,
    // historyApiFallback: true,//开发环境是否访问到history
    /* 自动打开浏览器 */
    open: false,
    overlay: {
      warning: false,
      error: true
    },
    /* 跨域代理 */
    proxy: {
      '/api': {
        /* 目标代理服务器地址 */
        target: 'https://api.vvhan.com/api',
        // target: "http://172.16.25.6:11014",
        /* 允许跨域 */
        changeOrigin: true,
        ws: true, // proxy websockets
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}
